package com.xkdx.guangguang.presistence.updatebrand;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONArray;
import org.json.JSONObject;

import com.xkdx.guangguang.module.network.AbsModule;
import com.xkdx.guangguang.shareclass.BrandDetail;

public class UpdateBrandModule extends AbsModule {
	public List<BrandDetail> list;
	public String updateTime;

	@Override
	public void parseData() throws Exception {
		backJson = (JSONArray) result;
		try {
			for (int i = 0; i < backJson.length(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("getUpdatedBrandList")) {
					list = parseBrandList(jsonObj.getJSONObject("Content"));
				}

			}
		} catch (Exception e) {
			throw e;
		}

	}

	private List<BrandDetail> parseBrandList(JSONObject person) throws Exception{
		ArrayList<BrandDetail> list = new ArrayList<BrandDetail>();
		try {
			JSONObject stuts = (JSONObject) person.get("Result");
			JSONArray jsonArray = (JSONArray) stuts.getJSONArray("ListInfo");
			JSONObject time = stuts.getJSONObject("DetailInfo");
			updateTime = time.getString("UpdateTime");
			for (int i = 0; i < jsonArray.length(); i++) {
				JSONObject item = (JSONObject) jsonArray.opt(i);
				BrandDetail brandDetail = new BrandDetail();
				brandDetail.setBrandID(Integer.valueOf(item.getString("BrandID")));
				brandDetail.setBrandName(item.getString("BrandName"));
				brandDetail.setLogo(item.getString("Logo"));
				brandDetail.setOrderNum(Integer.valueOf(item.getString("OrderNum")));
				brandDetail.setIsDeleted("IsDeleted");
				brandDetail.setAtoZ(item.getString("AtoZ"));
				brandDetail.setBrandNameEn(item.getString("BrandNameEn"));
				brandDetail.setBrandSimpleName(item.getString("BrandSimpleName"));
				list.add(brandDetail);
			}

		} catch (Exception e) {
			throw e;
		}
		return list;
	}

}
